package com.atguigu.gulimall.seckill.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.seckill.service.UpSeckillScheduleService;
import com.atguigu.gulimall.seckill.to.SeckillSkuRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SeckillController {

     @Autowired
     UpSeckillScheduleService upSeckillScheduleService;

    /**
     * 获取当前 时间场次的秒杀商品渲染在页面上
     * @return
     */
     @GetMapping("/currentseckillskus")
      public R getCurrentSeckillSkus(){
          List<SeckillSkuRedisTo> skus=upSeckillScheduleService.getCurrentSeckillSkus();
          return R.ok().setData(skus);
      }

    /**
     * 点击 商品详情  时查询获取 该商品是否关联 秒杀信息
     * @param skuId
     * @return
     */
     @GetMapping("/seckill/sku/{skuId}")
     public R getSeckillRelationSku(@PathVariable("skuId") Long skuId){
         SeckillSkuRedisTo seckillSkuRedisTo=upSeckillScheduleService.getSeckillRelationSku(skuId);
         return R.ok().setData(seckillSkuRedisTo);
     }

    /**
     * 秒杀抢购 接口
     * @param killId   由 场次id + 商品id
     * @param key    秒杀抢购的随机码
     * @param num  抢购数量
     * @return
     */
     @GetMapping("/kill")
     public R seckill(@RequestParam("killId")String killId,
                      @RequestParam("key")String key,
                      @RequestParam("num") Integer num){
      String orderSn= upSeckillScheduleService.seckill(killId,key,num);
      return null;
    }



}
